package 二分查找;

/**
 * @author tmh
 * @date 2024/12/5 20:59
 * @description
 */
public class T74搜索二维矩阵 {
    public static boolean searchMatrix(int[][] mat, int t) {
        int n = mat.length;
        int m = mat[0].length;
        for (int i = 0; i < n; i++) {
            int left = 0;
            int right = m - 1;
            while (left <= right) {
                int mid = left + right + 1 >> 1;
                if (mat[i][mid] > t) {
                    right = mid - 1;
                } else if (mat[i][mid] < t) {
                    left = left + 1;
                } else {
                    return true;
                }
            }
        }
        return false;
    }
}
